<?php 
$weekarr = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
$week = $weekarr[date("w")];
?>
<script type="text/javascript">
    function readURL(input,id) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                $('#'+id).html(input.value);
            };
            reader.readAsDataURL(input.files[0]);
        }
    }
    function readURL2(input,id) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                $('#'+id).val(input.value);
            };
            reader.readAsDataURL(input.files[0]);
        }
    }
</script>
<style>
.input-div table tr{display:block;}    
</style>
<div class="positiondiv">
    <table>
        <tr>
            <td class="td-left">
                <img src="<?=base_url()?>resource/img/home_ico.png" width="21" height="17">
                Data Entry > <a href="<?=base_url()?>index/index">Candidate</a> > Candidate Detail
            </td>
            <td class="td-right">
                <img src="<?=base_url()?>resource/img/menu2.png" width="27" height="24">Today is <?=$week?>,<?=date('M d,Y')?>
            </td>
        </tr>
    </table>
</div>
<div class="detail-div">
    <div class="detail-menu">
        <div class="active1 detail-active" id="menu1">Worker Information</div>
        <div class="active2 single-menu" id="menu2">Attachment List</div>
        <div style="width:0px;"></div>
    </div>
    <div class="input-div">
        <form action="<?=base_url('index/candidate_detail/'.$candidate['id'])?>" enctype="multipart/from-data" method="post" onsubmit="return checkform0()">
            <table>
                <tr><td colspan="2"><h3>.Candidate</h3></td></tr>
                <tr>
                    <td class="nametd">Nationality:</td>
                    <td>
                        <input type="radio" name="nationality" value="1" id="Malaysia"/><label for="Malaysia">Malaysia</label>
                        <input type="radio" name="nationality" value="2" id="China"/><label for="China">China</label>
                        <input type="radio" name="nationality" value="3" id="Vietnam"/><label for="Vietnam">Vietnam</label>
                        <input type="radio" name="nationality" value="4" id="Myanmar"/><label for="Myanmar">Myanmar</label>
                        <input type="radio" name="nationality" value="6" id="Other"/>
                        <input type="text" id="othernationality" name="othernationality" placeholder="Other" style="width:100px;" />
                        <span id="nationalitymsg" class="err"></span>
                    </td>
                </tr>
                <tr><td class="nametd">Name:</td><td><input type="text" name="name" value="<?=$candidate['name']?>" /><span id="namemsg" class="err">*</span></td></tr>
                <tr>
                    <td class="nametd">Intermediary:</td>
                    <td>
<!--                        <div class="field">
                            <input type="text" name="intermediary" value="<?=$thisintermediary['name']?>"/>
                            <input type="hidden" name="companyid" value="<?=$candidate['companyid']?>" />
                        </div>-->
                        <select name="companyid" id="companyid" style="width:200px;">
                            <option value="0">-SELECT-
                            <?php
                                for($i = 1;$i < count($intermediary);$i++){
                                    echo "<option value='".$intermediary[$i]['id']."'>".$intermediary[$i]['name'];
                                }
                            ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="nametd">Gender:</td>
                    <td>
                        <input type="radio" name="gender" value="1" id="man"/><label for="man">M</label>
                        <input type="radio" name="gender" value="2" id="female"/><label for="female">F</label>
                    </td>
                </tr>
                <tr>
                    <td class="nametd">Birthday:</td>
                    <td>
                        <select name="month" id="month">
                            <option value="0">-Month-
                            <?php
                                for($i = 1;$i < 13;$i++){
                                    echo "<option value='".$i."'>".$i;
                                }
                            ?>
                        </select>
                        <select name="day" id="day">
                            <option value="0">-Day-
                            <?php
                                for($i = 1;$i < 32;$i++){
                                    echo "<option value='".$i."'>".$i;
                                }
                            ?>
                        </select>
                        <select name="year" id="year">
                            <option value="0">-Year-
                            <?php
                                for($i = 1950;$i < 2017;$i++){
                                    echo "<option value='".$i."'>".$i;
                                }
                            ?>
                        </select>
                    </td>
                </tr>
                <tr><td class="nametd">Expect Position:</td><td><input type="text" name="position" value="<?=$candidate['position']?>"/></td></tr>
                <tr><td class="nametd">Speciality:</td><td><input type="text" name="speciality" value="<?=$candidate['speciality']?>"/></td></tr>
                <tr><td class="nametd">Work Address:</td><td><input type="text" name="workaddress" value="<?=$candidate['workaddress']?>"/></td></tr>
                <tr>
                    <td class="nametd">Location:</td>
                    <td>
                        <input type="radio" name="location" value="0" id="Oversea"/>
                        <label for="Oversea">Overseas</label>
                        <input type="radio" name="location" value="1" id="Singapore"/>
                        <label for="Singapore">Singapore</label>
                    </td>
                </tr>
                <tr>
                    <td class="nametd">Status:</td>
                    <td>
                        <input type="radio" name="status" checked="checked" value="0" id="applicable"/>
                        <label for="applicable">Applicable</label>
                        <input type="radio" name="status" value="1" id="NA"/>
                        <label for="NA">N.A.</label>
                    </td>
                </tr>
                <tr style="display:none;" id="passtypetr">
                    <td class="nametd">Pass Type:</td>
                    <td>
                        <select name="passtype" id="passtype">
                            <option value="1">WP
                            <option value="2">SP
                            <option value="3">EP
                            <option value="4">SVP
                            <option value="5">DP
                            <option value="6">Other
                        </select>
                    </td>
                </tr>
                <tr><td class="nametd">Comments:</td>
                    <td>
                        <textarea name="comment"><?=$candidate['comment']?></textarea>
                    </td>
                </tr>
                <tr><td class="nametd">Ever been SGP:</td>
                    <td>
                    <input type="radio" name="overbeensgp" value="0" id="syes"/><label for="syes">Yes</label>
                    <input type="radio" name="overbeensgp" value="1" id="sno"/><label for="sno">No</label>
                    </td>
                </tr>
                <tr><td class="nametd">Interviewer:</td><td><label><?=$candidate['employeename']['username']?></label></td></tr>
                <tr><td class="nametd">Create Time:</td><td><label><?=date("M d,Y",$candidate['createtime'])?></label></td></tr>
                <tr><td class="nametd">Update Time:</td><td><label><?=date("M d,Y",$candidate['updatetime'])?></label></td></tr>
                <tr><td></td><td><input type="submit" value="Save"/></td></tr>
            </table>
        </form>
    </div>
    <div class="list-div" style="display:none;">
        <table class="list-table">
            <tr>
                <th width="200">Worker Name</th>
                <!--<th width="200">Attachment Name</th>-->
                <th>Attachment</th>
                <th width="100"></th>
            </tr>
            <?php foreach ($attachments as $key => $value) {?>
            <tr>
                <td><?=$candidate['name']?></td>
                <!--<td><?=$value['title']?></td>-->
                <td><a href="<?=base_url("index/downfile").'/'.$value['path']?>" target="_blank"><?=$value['path']?></a></td>
                <td>
                    <a href="<?=base_url('index/deleteattachment').'/'.$value['id'].'/'.$candidate['id'] ?>" class="buttona">
                        <img src="<?=base_url()?>resource/img/delete.png"/>delete
                    </a>
                </td>
            </tr>
            <?php }?>
            <tr>
                <td></td>
                <td colspan="2" class="relative" style="text-align:left;">
                    <form action="<?=base_url('index/newattachment/'.$candidate['id'])?>" method="post" enctype="multipart/form-data" onsubmit="return checkform()">
                        <input type="text" placeholder="attachment path" id="attachmentpath" style="width:540px;margin-left:30px;margin-right:30px;"/>
                        <img src="<?=base_url()?>resource/img/upload.png" width="25" height="29" style="position:absolute;left:545px;top:3px;" />
                        <input type="file" id="path" class="inputfile" name="path" size="20" onchange="readURL2(this,'attachmentpath');" 
                               style="position:absolute;width:25px;height:29px;left:545px;top:3px;cursor:pointer;opacity:0;filter:alpha(opacity=0);"/>
<!--                        <select name="type" style="width:100px;height:30px;border-radius:5px;border:1px solid #c9c9c9;">
                            <option value="0">Normal
                            <?php
                                $flag = false;
                                foreach ($attachments as $key => $value) {
                                    if($value['type'] == 1){
                                        $flag = true;
                                    }
                                }
                                if(!$flag){?>
                                    <option value="1">Confirmation Letter
                            <?php }?>
                        </select>-->
                        <input type="hidden" name="type" value="0" />
                        <input type="hidden" name="title" value="WokerNormal" />
                        <input type="submit" style="position:absolute;width:29px;height:29px;background:#ffffff url(<?=base_url()?>resource/img/save.png) no-repeat;
                               background-repeat:round;right:40px;top:4px;cursor:pointer;border:none;" value=""/>
                    </form>
                </td>
            </tr>
        </table>
    </div>
</div>
<script>
$("input[name='nationality']:eq(<?=$candidate['nationality']-1?>)").attr("checked","checked");
if("<?=$candidate['nationality']-1?>" != 0 && "<?=$candidate['nationality']-1?>" != 1 && "<?=$candidate['nationality']-1?>" != 2 && "<?=$candidate['nationality']-1?>" != 3){
    $("input[name='nationality']:eq(4)").attr("checked","checked");
    $("#othernationality").val("<?=$candidate['nationality']?>");
}
$("input[name='gender']:eq(<?=$candidate['gender']-1?>)").attr("checked","checked");
$("input[name='location']:eq(<?=$candidate['location']?>)").attr("checked","checked");
$("input[name='status']:eq(<?=$candidate['status']?>)").attr("checked","checked");
$("input[name='overbeensgp']:eq(<?=$candidate['overbeensgp']?>)").attr("checked","checked");
if("<?=$candidate['location']?>" == 1){
    $("#passtypetr").css("display","block");
    $("#passtype").val("<?=$candidate['passtype']?>");
}
$("#companyid").val("<?=$candidate['companyid']?>");
var birthday = "<?=$candidate['birthday']?>";
var birthdays = birthday.split("-");
$("#month").val(birthdays[1]);
$("#day").val(birthdays[2]);
$("#year").val(birthdays[0]);

cutmenu();
function cutmenu(){
    $(".single-menu").click(function(){
        $(".detail-active").removeClass("detail-active").addClass("single-menu");
        $(this).removeClass("single-menu").addClass("detail-active");
        var id = $(this).attr("id");
        if(id == "menu1"){
            $(".input-div").css("display","block");
            $(".list-div").css("display","none");
        }else{
            $(".input-div").css("display","none");
            $(".list-div").css("display","block");
        }
        cutmenu();
    });
}

function checkform(){
    if($.trim($("#attachmentpath").val()) == ""){
        alert("Please upload file!");
        return false;
    }
    return true;
}

$("input[name='location']").click(function(){
    if($("input[name='location']:checked").val() == 1){
        $("#passtypetr").css("display","block");
    }else{
        $("#passtypetr").css("display","none");
    }
});

function checkform0(){
    var flag = true;
    var name = $.trim($("input[name='name']").val());
    if(name == ''){
        flag = false;
        $("#namemsg").html("Candidate name can not be null!");
    }else{
        $("#namemsg").html("*");
    }
    
    if($("input[name='nationality']:checked").val() == 6 && $.trim($("#othernationality").val()) == ''){
        flag = false;
        $("#nationalitymsg").html("Please input other nationality!");
    }else{
        $("#nationalitymsg").html('');
    }
    return flag;
}
</script>
